<template>
  <el-button :disabled="lock" @click="clickEvent">
    <slot v-if="lock===false"></slot>
    <span v-if="lock===true">{{lockTextValue}}</span>
  </el-button>
</template>

<script>
  export default {
    name: "ElTimeLockButton",
    data() {
      return {
        lock: false,
        lockTextValue: null,
      }
    },
    props: {
      'lockText': {},
      'lockTime': {}
    }
    ,
    methods: {
      clickEvent(evt) {
        this.lock = true;
        let lockTime = this.lockTime;
        this.lockTextValue = this.lockText + '(' + lockTime + ')';
        lockTime--;
        let buttonLock = setInterval(() => {
          this.lockTextValue = this.lockText + '(' + lockTime + ')';
          lockTime--;
          if (lockTime <= 0) {
            this.lock = false;
            clearInterval(buttonLock);
          }
        }, 1000);
        this.$emit('click', evt);
      }
    }
  }
</script>

<style scoped>

</style>
